import java.util.concurrent.atomic.AtomicInteger;

/**
 * print 1 to 100
 * @param
 * @Date ：created in 2022/4/7 11:39
 * @return
 */
public class DoubleThread100 {

    public static void main(String[] args) {
        AtomicInteger num=new AtomicInteger(0);

        Thread printThread1=new PrintThread();
        Thread printThread2=new PrintThread();
        printThread1.start();
        printThread2.start();
    }
    public static class PrintThread extends Thread{
        static int number=1;
        static Object obj=new Object();
        @Override
        public void run() {
            while (true){
                synchronized (obj){
                    obj.notify();//唤醒wait
                    if (number<=100){
                        System.out.println(Thread.currentThread().getName()+":"+number);
                        number++;
                        try {
                            //释放锁
                            obj.wait();
                        }catch (InterruptedException e){
                            e.printStackTrace();
                        }
                    }else {
                        break;
                    }
                }
            }
        }
    }
}
